print("Runoob")
#单行注释
print("Hello,python！")#结尾注释
'''
多行注释
'''
print("Hello,python！")
"""
多行注释，也可以这样
"""
if True:
    print("True")
else:
    print("False")
'''
多行语句，可用反斜杠 
total = item_one + \
        item_two + \
        item_three
'''
"""
四种数据类型：整数、布尔型、浮点数和复数
    1.int
    2.boot
    3.float
    4.complex
"""
str = "我是字符"
print(str)
paragraph = """
    我是一个段落
    我由多行组成
    """
print(paragraph)
print(str[0:2:1])#输出第一个到第三个字符，步长为1
print(str[-1:1])
print(str+"，你好")

# input("\n\n按下enter键后退出！")
import sys; x= 'runoob'; sys.stdout.write(x+'\n')
#同一行多语句，用分号隔开
print("Hello World!", end="")
print("Hello World!", end="\n")
print("我是结尾")

from sys import path
# print("python path:",path)
#python中变量不需要声明类型
"""
标准数据类型
1.Number 数字
2.String 字符串
3.bool 布尔类型
4.List 列表
5.Tuple 元组
6.Dictionary 字典
"""
a = 1111
isTrue = isinstance(a,int)
print(isTrue)

list = ['1','2','3','4','5']
print(list)
print(list[0:2] *3)
print(list[:-1])
print(str[-1::-1])
def reverse(str):
    return str[::-1]
print(reverse("runoob"))
tuple = ('abc','dcd','fhg')
print(tuple)
str="1,2,3,4,5"
print(str.split(","))

print("我叫%s,今年%d岁"%("runoob",1))
str = "runboo"
print(f"hello {str}")
print(f"{str:>10}")

a = [1,2]
b = [1,2]
print(a == b)
a.extend([3])
print(a)
print(a.index(3))
del a[0]
print(a)
a.remove(2)
print(a)

#30以内可以被3整除的整数
vmm = [i for i in range(30) if i%3 == 0]
print(vmm)

def f(x):
    return x*x
print(f(2))
for i in range(1, 10):
    for j in range(1, i + 1):
        print(f"{j} * {i} = {i * j}", end="\t")
    print()

print('i want to control the world')

#数据库操作  python2.x 连接方式
# import mysql.connector
# mydb = mysql.connector.connect(
#     host="localhost",
#     user="root",
#     passwd="123456",
#     database="shop_mall"
# )
# print(mydb.is_connected())
# mycursor = mydb.cursor()
# mycursor.execute("select * from mgy_address")
# result = mycursor.fetchall()
# for i in result:
#     print(i)
# mycursor.execute("SHOW DATABASES")
# for x in mycursor:
#     print(x)

# import pymysql
# pydb = pymysql.connect(host='localhost', user='root', password='123456', database='shop_mall')
# sqlcursor = pydb.cursor()
# sqlcursor.execute("SHOW TABLES")
# for x in sqlcursor:
#     print(x)
# sql = "select * from mgy_address"
# sqlcursor.execute(sql)
# result = sqlcursor.fetchall()
# for i in result:
#     print(i)

# SQL删除记录语句
# sql = "DELETE FROM EMPLOYEE WHERE AGE > %s" % (20)
# try:
#    # 执行SQL语句
#    cursor.execute(sql)
#    # 向数据库提交
#    db.commit()
# except:
#    # 发生错误时回滚
#    db.rollback()

# pydb.close()

import socket
import sys
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
# port = 9999
# serverSocket.bind((host, port))
# serverSocket.listen(5)
# while True:
#     clientSocket, address = serverSocket.accept()
#     print("连接地址：%s" % str(address))
#     msg = '欢迎访问菜鸟教程！' + "\r\n"
#     clientSocket.send(msg.encode('utf-8'))
#     clientSocket.close()
# print("host",host)
# serverSocket.connect_ex((host, 80))
# msg = socketserver.recv(1024)
# socketserver.close()
# print(msg.decode('utf-8'))

#多线程
# import threading
# import time
# def print_time(threadName, delay):
#     count = 0
#     while count < 5:
#         time.sleep(delay)
#         count += 1
#         print("%s: %s" % (threadName, time.ctime(time.time())))
#
# thread = threading.Thread(target=print_time, args=("Thread-1", 1))
# thread.start()
# thread.join()

from urllib.request import urlopen
url = urlopen("http://www.baidu.com/")
print(url.getcode())

import urllib.robotparser
rp = urllib.robotparser.RobotFileParser()
rp.set_url(url="https://www.runoob.com/robots.txt")
print(rp.read())

# 检查某个 URL 是否被允许访问
allowed = rp.can_fetch("*", "https://www.runoob.com/")
print("Can fetch:", allowed)

import requests
response = requests.get("https://www.runoob.com/")
print(response.reason)

from selenium import webdriver
from selenium.webdriver.common.by import By  # 导入 By 模块
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 设置驱动的路径，启动浏览器
service = ChromeService()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)

try:
    # 打开百度首页
    driver.get("https://www.baidu.com")

    # 查找搜索框元素
    search_box = driver.find_element(By.ID, "kw")

    # 输入搜索内容
    search_box.send_keys("天气")

    # 提交搜索表单
    search_box.send_keys(Keys.RETURN)

    # 等待搜索结果加载
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "content_left"))
    )

    # 打印页面标题
    print("页面标题是:", driver.title)

finally:
    # 关闭浏览器
    # driver.quit()
    #关闭当前窗口
    # driver.close()
    pass

# from bs4 import BeautifulSoup
# import requests
# import lxml
#
# url = 'https://www.baidu.com/'
# response = requests.get(url)
# print(response.content)
# import chardet #自动检查编码，防止乱码
# encoding = chardet.detect(response.content)['encoding']
# response.encoding = encoding
# if response.status_code == 200:
#     soup = BeautifulSoup(response.text, 'lxml')
#     print(soup.title.string)
# else:
#     print('请求失败')

